package com.weiaibenpao.demo.chislim.ui.adapter;

import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.weiaibenpao.demo.chislim.R;
import com.weiaibenpao.demo.chislim.bean.Message;
import com.weiaibenpao.demo.chislim.utils.Utils;


/**
 * Created by Administrator on 2018/1/3.
 */

public class MessageListAdapter extends BaseQuickAdapter<Message, BaseViewHolder> {


    public MessageListAdapter() {
        super(R.layout.item_message, null);
    }

    @Override
    protected void convert(BaseViewHolder baseViewHolder, Message message) {
        baseViewHolder.setText(R.id.tv_nickname, message.getUserName());
        if (message.getInfoType() == 0) {
            baseViewHolder.getView(R.id.tv_content).setVisibility(View.GONE);
            baseViewHolder.getView(R.id.iv_like).setVisibility(View.VISIBLE);
        } else {
            baseViewHolder.getView(R.id.tv_content).setVisibility(View.VISIBLE);
            baseViewHolder.getView(R.id.iv_like).setVisibility(View.GONE);
            baseViewHolder.setText(R.id.tv_content, message.getComText());
        }
        baseViewHolder.setText(R.id.post_time, Utils.getFormattedTime(message.getCreateTime(), "yyyy-MM-dd HH:mm:ss"));
        Glide
                .with(baseViewHolder.getView(R.id.avatar).getContext())
                .load(message.getUserImage())
                .into((ImageView) baseViewHolder.getView(R.id.avatar));
        Glide
                .with(baseViewHolder.getView(R.id.iv_moment_image).getContext())
                .load(message.getInfoUrl())
//                .apply(new RequestOptions().centerCrop())
                .into((ImageView) baseViewHolder.getView(R.id.iv_moment_image));
    }
}
